#!/usr/bin/env ipython

import os
import sys
import random

sys.path.append('../../lib')
sys.path.append(os.getenv("HOME")+'/lib')

from flgrcore import *
from flgrmorpho import *
from flgrrtview import *

def buildColorTable():
    r=[]
    g=[]
    b=[]
    for i in range(256):
        r.append(255-i)
        g.append(255-i)
        b.append(255-i)
    #random.shuffle(r)
    #random.shuffle(g)
    #random.shuffle(b)
    return r,g,b


imin = flgr2d_load_pgm('../../apps/images/gray/cameraman.pgm','input')
imin2 = FLGR_Data2D(imin.size_y,imin.size_x,'fgUINT8','eroded')
imin3 = FLGR_Data2D(imin.size_y,imin.size_x,'fgUINT8','test')
nhb1 = FLGR_Data2D(3,3,'fgUINT8','diam','DIAMOND','8-connexity')
nhb2 = FLGR_Data2D(3,3,'fgUINT8','square','RECT','8-connexity')

scr0 = flgr2d_rtview_create(imin3, 1, 2)

r,g,b = buildColorTable()
flgr2d_rtview_set_palette(scr0,r,g,b)

flgr2d_rtview_refresh(scr0, imin, 0, 0)


flgr2d_copy(imin3,imin)
for i in range(0,100) :
    flgr2d_dilate(imin2,imin3,nhb1)
    flgr2d_copy(imin3,imin2)
    flgr2d_rtview_refresh(scr0, imin3, 0, 1)

    
    flgr2d_dilate(imin2,imin3,nhb2)
    flgr2d_copy(imin3,imin2)
    flgr2d_rtview_refresh(scr0, imin3, 0, 1)



